import {DataRouter} from "../../../script/frame/dataSource/DataRouter";
import {GuiKeys} from "../../../script/controller/model/ControllerOpt";
import Configer from "../../../script/frame/apiModel/config/Configer";
import {UIConfigKey} from "../../../script/constant/UIConfig";
import * as React from "../../../script/frame/apiModel/gui/React";
import {ResourceKey} from "../../../script/constant/ResourceConstant";
import {View} from "../../../script/frame/apiModel/gui/React";

interface IProp {
    x: number,
    y: number,
    achId: string,
}
interface IState {
}

export default class AchInfoPage extends React.Element<IProp, IState> {

    render = () => {
        const yMargin = 0.01;
        const backSize = { h: 0, w: 0.3 }
        const backPos = { x: this.props.x, y: this.props.y }
        const xPadding = 0.0064;
        const fontSize = Configer.getUIConfig(UIConfigKey.fontSize);
        let retStr = '';
        const achData = DataRouter.getAchievementDataByAchievementId(this.props.achId);
        const name = achData?.name;
        if (name) {
            retStr = retStr + `${name}\n\n`;
        }
        if (achData?.descript) {
            const descriptLineStr = achData.descript;
            retStr = retStr + `${descriptLineStr}\n`;
        } else {
            const descriptLineStr = '成就描述为空';
            retStr = retStr + `${descriptLineStr}\n`;
        }
        const retLineArr = retStr.split('\n');
        const retLineNum = retLineArr.length - 1;
        const retSize = { h: retLineNum * fontSize, w: backSize.w - xPadding * 2 }
        backSize.h = backSize.h + retSize.h + yMargin * 2;
        const goodInfoPagePath = Configer.getResource(ResourceKey.infoPagePath);

        return <View   key={GuiKeys.achInfo} style={{ backgroundImage: goodInfoPagePath, left: backPos.x, top: backPos.y, width: backSize.w, height: backSize.h }}>
            <View   key={GuiKeys.achInfoText} style={{ marginL: 0.0125, marginT: yMargin, width: retSize.w, height: retSize.h }}>{retStr}</View>
        </View>
    }
    // show = (player: player, x: number, y: number, achId: string) => {
    //     const yMargin = 0.01;
    //     const backSize = { h: 0, w: 0.2 }
    //     const backPos = { x, y }
    //     // const backPos = { x: 0.7, y: 0.45 }
    //     const childProps: GuiProps[] = []
    //     const xPadding = 0.004;
    //     const fontSize = Configer.getUIConfig(ResourceKey.fontSize);
    //     if (achId) {
    //         let retStr = '';
    //         const achData = DataRouter.getAchievementDataByAchievementId(achId);
    //         const name = achData.name;
    //         if (name) {
    //             retStr = retStr + `${name}\n\n`;
    //         }
    //         // let levelStr;
    //         // if (unitData.good_level) {
    //         //     const hero = GlobalEnv.getHero(player);
    //         //     if (hero && GetHeroLevel(hero) >= unitData.good_level) {
    //         //         levelStr = `|cff20c000穿戴等级: ${unitData.good_level}|r`;
    //         //     } else {
    //         //         levelStr = `|cffff0303穿戴等级: ${unitData.good_level}|r`;
    //         //     }
    //         //     retStr = retStr + `${levelStr}\n`;
    //         // }
    //         // const positionStr = Util.getNameByPosition(unitData.position);
    //         // retStr = retStr + `${positionStr}\n`;
    //
    //         if (achData.descript) {
    //             const descriptLineStr = achData.descript;
    //             retStr = retStr + `${descriptLineStr}\n`;
    //         } else {
    //             const descriptLineStr = '成就描述为空';
    //             retStr = retStr + `${descriptLineStr}\n`;
    //         }
    //
    //         const retLineArr = retStr.split('\n');
    //         const retLineNum = retLineArr.length - 1;
    //         const retSize = { h: retLineNum * fontSize, w: backSize.w - xPadding * 2 }
    //         backSize.h = backSize.h + retSize.h + yMargin * 2;
    //         backPos.x = backPos.x - backSize.w;
    //         backPos.y = backPos.y + backSize.h;
    //         const retProp: GuiProps = {
    //             text: retStr,
    //             childNum: 0,
    //             childProps: [],
    //             id: this.getName(),
    //
    //             margin: { l: 0.01, t: yMargin },
    //             size: retSize,
    //         };
    //         childProps.push(retProp);
    //     }
    //     const goodInfoPagePath = Configer.getUIConfig(ResourceKey.infoPagePath);
    //     const backProp: GuiProps = {
    //         backgroundImage: goodInfoPagePath,
    //         childProps,
    //         childNum: 1,
    //         id: this.getName(),
    //         position: backPos,
    //
    //         size: { w: backSize.w, h: backSize.h },
    //         padding: { l: 0, t: 0 },
    //         colNum: 1
    //     };
    //     this.toRender(player, backProp, DzGetGameUI());
    // }
}